<template>
    <div id="waveplanpanel">
        <div class="title">
            <div>
                <el-date-picker v-model="timeNow" type="month" placeholder="" @change="changeMonth">
                </el-date-picker>
                <el-button @click="upWeek">上周</el-button>
                <!-- <el-button class="choose" v-show="isNow">本周</el-button> -->
                <el-button @click="downWeek">下周</el-button>
            </div>
            <div>
                <el-button class="choose" :disabled="!this.btnPermNameList.includes('WM05010401')" @click="create">创建波次计划</el-button>
                <!-- <el-button>波次计划管理</el-button> -->
            </div>
        </div>
        <div class="calendar-box" :style="{ 'height': height + 'px' }">
            <div v-for="(item, index) in calTitleList" :key="index" class="cal-title" :style="{ 'width': width + 'px' }"
                :class="item.toDay ? 'active' : ''">
                {{ item.date }} <span v-if="item.toDay">(今天)</span>
                <div class="cal-detail" :style="{ 'height': height - 46 + 'px' }">
                    <div v-for="(con, i) in item.outWaveStrategyPlanList" :key="i" class="cal-detail-box">
                        <div class="con-title">{{ con.planName }}</div>
                        <div class="con-info">
                            <p><span>时间区间:</span> {{ getTime(con.startRuningTime) }} 至 {{
                                    getTime(con.endRuningTime)
                            }} </p>
                            <p><span>刷新频率:</span> {{ con.refreshFrequency }} <span>分钟/次</span></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { queryThisWeekSPlanData } from "@/api/business/wave"
import { formatDate } from "@/utils/index.js";
import baseMixin from "@/mixins/BaseMixin";
export default {
  mixins: [baseMixin],
    name: "waveplanpanel",
    data() {
        return {
            timeNow: "",
            calTitleList: [],
            height: 0,
            width: 0,
            week: 0,
            now: null
        }
    },
    mounted() {
        this.height = this.getHeight(window, 10);
        this.width = (window.innerWidth - 280 - 48) / 7;
        this.$store.commit("setSkip", {});
        this.$store.commit("setRouteId", "");
        this.$store.commit("setNewFlag", false);
        this.$store.commit("setRouteData", {});
        // 首次进入页面获取当前时间并转化为时间戳
        this.now = new Date().getTime();
        this.timeNow = new Date().getTime();
        // 根据当前时间戳获取本周计划数据
        this.getThisWeekSPlanData(this.now);
    },
    methods: {
        getThisWeekSPlanData(week) {
            queryThisWeekSPlanData(week).then(res => {
                    this.calTitleList = res.list;
                
            })
        },
        create() {
            this.$store.commit("setNewFlag", true);
            this.$router.push({ name: 'waveplansmaintenanceDeawer' });
        },
        changeMonth(data) {
            this.now = data.getTime();
            this.getThisWeekSPlanData(data.getTime());
        },
        upWeek() {
            this.now = this.now - 7 * 24 * 60 * 60 * 1000;
            this.getThisWeekSPlanData(this.now);
        },
        downWeek() {
            this.now = this.now + 7 * 24 * 60 * 60 * 1000;
            this.getThisWeekSPlanData(this.now);
        },
        getTime(time) {
            let str = formatDate(time);
            return str.slice(11);
        }
    }
}
</script>

<style lang="scss" scoped>
#waveplanpanel {
    height: 100%;
    overflow: hidden;

    .title {
        width: 100%;
        background: #e4e4e4e5;
        height: 40px;
        border-radius: 8px;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .el-date-editor {
            width: 125px;

            ::v-deep .el-input__inner {
                border: none;
                background: #ffffff00;
                height: 30px;
                line-height: 30px;
                padding: 0 10px;
                font-size: 20px;
                color: #409eff;
            }
        }

        .el-button {
            width: auto;
            padding: 0 8px;

            &.choose {
                color: #409eff;
            }
        }
    }

    .calendar-box {
        width: 100%;
        overflow-y: auto;

        &::-webkit-scrollbar {
            width: 0 !important;
        }

        .cal-title {
            text-align: center;
            margin: 8px 0 8px 8px;
            float: left;
            background: #e4e4e4e5;
            line-height: 30px;
            height: 30px;

            &:nth-child(1) {
                margin: 8px 0 8px 0px;
            }

            &.active {
                color: #409eff;

                .cal-detail-box {
                    border-left: 3px solid #409eff !important;
                }
            }


            .cal-detail {
                width: 100%;


                .cal-detail-box {
                    height: 90px;
                    width: 100%;
                    margin-bottom: 8px;
                    background: #fff;
                    border-left: 3px solid #666666;

                    &:nth-child(1) {
                        margin-top: 8px;
                    }

                    .con-title {
                        height: 30px;
                        line-height: 30px;
                        text-align: left;
                        color: #000;
                        padding-left: 4px;
                        font-weight: bold;
                        border: .5px solid #dfdfdf;
                    }

                    .con-info {
                        height: 60px;

                        p {
                            height: 30px;
                            line-height: 30px;
                            margin: 0;
                            color: #000;
                            border: .5px solid #dfdfdf;
                            text-align: left;
                            padding-left: 4px;

                            span {
                                color: gray;
                            }
                        }
                    }
                }
            }
        }
    }
}
</style>